package com.traceability.trace.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.traceability.common.annotation.Log;
import com.traceability.common.core.controller.BaseController;
import com.traceability.common.core.domain.AjaxResult;
import com.traceability.common.enums.BusinessType;
import com.traceability.trace.domain.Logistics;
import com.traceability.trace.service.ILogisticsService;
import com.traceability.common.utils.poi.ExcelUtil;
import com.traceability.common.core.page.TableDataInfo;

/**
 * 运输管理Controller
 * 
 * @author xulin
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/traceability-trace/logistics")
public class LogisticsController extends BaseController
{
    @Autowired
    private ILogisticsService logisticsService;

    /**
     * 查询运输管理列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:logistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(Logistics logistics)
    {
        startPage();
        List<Logistics> list = logisticsService.selectLogisticsList(logistics);
        return getDataTable(list);
    }

    /**
     * 导出运输管理列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:logistics:export')")
    @Log(title = "运输管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Logistics logistics)
    {
        List<Logistics> list = logisticsService.selectLogisticsList(logistics);
        ExcelUtil<Logistics> util = new ExcelUtil<Logistics>(Logistics.class);
        util.exportExcel(response, list, "运输管理数据");
    }

    /**
     * 获取运输管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:logistics:query')")
    @GetMapping(value = "/{logisticsId}")
    public AjaxResult getInfo(@PathVariable("logisticsId") Long logisticsId)
    {
        return success(logisticsService.selectLogisticsByLogisticsId(logisticsId));
    }

    /**
     * 新增运输管理
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:logistics:add')")
    @Log(title = "运输管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Logistics logistics)
    {
        return toAjax(logisticsService.insertLogistics(logistics));
    }

    /**
     * 修改运输管理
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:logistics:edit')")
    @Log(title = "运输管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Logistics logistics)
    {
        return toAjax(logisticsService.updateLogistics(logistics));
    }

    /**
     * 删除运输管理
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:logistics:remove')")
    @Log(title = "运输管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logisticsIds}")
    public AjaxResult remove(@PathVariable Long[] logisticsIds)
    {
        return toAjax(logisticsService.deleteLogisticsByLogisticsIds(logisticsIds));
    }
}
